package example.hello_security.login.service.impl;
import example.hello_security.login.bean.MyUser;
import example.hello_security.login.constant.UserConstant;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.HashMap;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    @Override
    public UserDetails loadUserByUsername( String username) throws UsernameNotFoundException {
        MyUser user=UserConstant.userMap.get( username );
        if(user==null){
            throw new UsernameNotFoundException( "用户不存在: " +username );
        }
        return User.builder()
                .username(user.getName())
                .password(user.getPassword())
                .build();
    }
}
